﻿//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using System.IO;


//namespace QQSDK
//{
//    public class IAPManager : MonoBehaviour
//    {
//        public List<PurchaseBean> purchaseList;
//        public string App_Name;
//        public string APP_ID;
//        public string Private_key;
//        public string Public_key;
//        public string purchaseFileName;
//#if UNITY_EDITOR || DEVELOP

//#elif UNITY_IOS

//#elif UNITY_ANDROID
//       AndroidJavaClass iapClass;
//#endif
//        private void Awake()
//        {
//            purchaseList = new List<PurchaseBean>();
//#if UNITY_EDITOR || DEVELOP

//#elif UNITY_IOS

//#elif UNITY_ANDROID
//#if CN
//            iapClass = new AndroidJavaClass("com.tapque.iapcn.IAPManager");
//            Init();
//#endif
//#endif
//        }
//        void Init()
//        {
//#if UNITY_EDITOR || DEVELOP
//            string folderName = Application.dataPath + "/Plugins/Android/assets";
//            string fileName = Path.Combine(folderName, "purchase.json");
//            LoadAllPurchaseInfo(File.ReadAllText(fileName));
//#elif UNITY_IOS

//#elif UNITY_ANDROID
//            iapClass.CallStatic("initIAPConfig",true,CommomUtils.currentlyActivity,purchaseFileName,App_Name,APP_ID,Private_key,Public_key);
//#endif
//        }
//        public void LoadAllPurchaseInfo(string jsonInfo)
//        {
//            List<object> list = Json.Deserialize(jsonInfo) as List<object>;
//            //foreach (var item in list)
//            //{
//            //    Dictionary<string, object> infos = item as Dictionary<string, object>;
//            //    PurchaseBean purchaseBean = new PurchaseBean();
//            //    purchaseBean.testProduct = infos["testProduct"].Equals("true");
//            //    purchaseBean.purchaseType = int.Parse(infos["purchaseType"].ToString());
//            //    purchaseBean.purchaseItemName = infos["purchaseItemName"].ToString();
//            //    purchaseBean.purchaseContent = infos["purchaseContent"].ToString();
//            //    purchaseBean.purchaseTotalPrice = double.Parse(infos["purchaseTotalPrice"].ToString());
//            //    purchaseBean.purchaseRealPrice = double.Parse(infos["purchaseRealPrice"].ToString());
//            //    purchaseBean.sequence = int.Parse(infos["sequence"].ToString());
//            //    if (!purchaseList.Contains(purchaseBean))
//            //        purchaseList.Add(purchaseBean);
//            //}
//        }
//        public  void PurchaseItem(int sequence)
//        {
//#if UNITY_EDITOR || DEVELOP

//#elif UNITY_IOS

//#elif UNITY_ANDROID
//            if(null!=iapClass)
//           iapClass.CallStatic("startBuy", CommomUtils.currentlyActivity,sequence);

//#endif
//        }
//        public  void PurchaseItem(string productID)
//        {
//#if UNITY_EDITOR || DEVELOP

//#elif UNITY_IOS

//#elif UNITY_ANDROID
//             if(null!=iapClass)
//            iapClass.CallStatic("startBuy", CommomUtils.currentlyActivity,productID);
//#endif
//        }
//        void Callback(string msg)
//        {
//            if (msg.Equals("Error"))
//            {
//                SDKFunc.LogError("购买出错");

//            } else if (msg.Equals("Cancel"))
//            {
//                SDKFunc.LogError("购买取消");
//            }else if (msg.StartsWith("Restore", System.StringComparison.Ordinal))
//            {
//                SDKFunc.LogError("恢复购买的完整信息:"+msg);
//                string[] msgArray = msg.Split(':');
//                for (int i = 0; i < purchaseList.Count; i++)
//                {
//                    if (msgArray[1].Equals(purchaseList[i].purchaseItemName))
//                    {
//                        if (purchaseList[i].purchaseType == 1)
//                        {
//                            SDKFunc.LogError("恢复购买：" + purchaseList[i].purchaseItemName);
//                        }
//                        else
//                        {
//                            SDKFunc.LogError("恢复购买失败，商品信息配置错误，请检查purchase.json文件中 " + purchaseList[i].purchaseItemName+ "商品类型配置是否正确");
//                        }
//                    }
//                }
//            }
//            else
//            {
//                for (int i = 0; i < purchaseList.Count; i++)
//                {
//                    if (msg.Equals(purchaseList[i].purchaseItemName))
//                    {
//                        SDKFunc.LogError("购买成功：" + purchaseList[i].purchaseItemName);
//                    }
//                }
//            }
//        }
//        void ReciverPurchaseInfo(string msg)
//        {
//            SDKFunc.LogError("接收到的商品信息："+msg);
//            LoadAllPurchaseInfo(msg);
//        }
//    }
//}

